package com.dc.designPattern._22_responsibilitychain.extend.extend1;

import cn.hutool.core.util.RandomUtil;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * Description: 古代女性有事请求过程
 *  故事背景：‘三从’ 是指 未嫁从父、既嫁从夫、夫死从子
 *      即：一位女性结婚之前听从于父亲，结婚之后听从于丈夫、丈夫死了还要听从于儿子
 *  代码演示如下：
 *
 * @author: gdc
 * @date: 2021/6/28
 * @version 1.0
 */
public class Client {

    public static void main(String[] args){
        List<IWomen> womenList = Lists.newArrayList();

        for (int i = 0; i < 10; i++) {
            womenList.add(new Women(RandomUtil.randomInt(4), "我要出去逛街..."));
        }

        IHandler father = new Father();
        IHandler husband = new Husband();
        IHandler son = new Son();

        for (IWomen women : womenList) {
            if (1 == women.getType()) {
                System.out.println("\n------------ 女儿向父亲请求 --------------");
                father.handleMessage(women);
            } else if (2 == women.getType()) {
                System.out.println("\n------------ 妻子向丈夫请求 --------------");
                husband.handleMessage(women);
            } else if (3 == women.getType()) {
                System.out.println("\n------------ 母亲向儿子请求 --------------");
                son.handleMessage(women);
            } else {
                throw new IllegalArgumentException();
            }
        }
    }
}
